package com.example.yyy

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import kotlinx.android.synthetic.main.activity_runnable.*

class RunnableActivity : AppCompatActivity() {

    private val handler = Handler()
    private var count = 0

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_runnable)
//        handler.post(counter)
        //简化类
        handler.post(Runnable {
            count ++
            runOnUiThread {
                tv_ar_count.text = "当前计数为：$count"
            }
        })
    }

    //内部类
    inner class Counter: Runnable{
        override fun run() {
            count++
            runOnUiThread {
                tv_ar_count.text = "当前计数为：$count"
            }
            handler.postDelayed(this,1000)
        }

    }
    //匿名内部类
    private val counter = object : Runnable{
        override fun run() {
            TODO("Not yet implemented")
        }

    }

}